home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / PCHDT_E3.CAB / HCscr_05.js < prev    next >
Encoding:
Text File  |  2003-02-21  |  5.7 KB  |  193 lines

  1.  
  2. function LoadWrapperParams(oSEMgr)
  3. {
  4.     var regBase = g_NAVBAR.GetSearchEngineConfig();
  5.  
  6.     // Load the number of results
  7.     var iNumResults = parseInt( pchealth.RegRead( regBase + "NumResults" ) );
  8.     if(isNaN( iNumResults ) == false && iNumResults >= 0)
  9.     {
  10.         oSEMgr.NumResult = iNumResults;
  11.     }
  12.     else
  13.     {
  14.         if (pchealth.UserSettings.IsDesktopVersion)
  15.             oSEMgr.NumResult = 15;
  16.         else
  17.             oSEMgr.NumResult = 50;
  18.     }
  19.  
  20.     // Load the number of results
  21.     if(pchealth.RegRead( regBase + "SearchHighlight" ) == "false")
  22.     {
  23.         g_NAVBAR.g_SearchHighlight = false;
  24.     }
  25.     else
  26.     {
  27.         g_NAVBAR.g_SearchHighlight = true;
  28.     }
  29.  
  30.     // Initialize search eng and get data
  31.     var g_oEnumEngine = oSEMgr.EnumEngine();
  32.     for(var oEnumEngine = new Enumerator(g_oEnumEngine); !oEnumEngine.atEnd(); oEnumEngine.moveNext())
  33.     {
  34.         var oSearchEng = oEnumEngine.item();
  35.  
  36.         // Load enable flag
  37.         var strBoolean = pchealth.RegRead( regBase + oSearchEng.ID + "\\" + "Enabled");
  38.         if ((strBoolean) && (strBoolean.toLowerCase() == "false"))
  39.             oSearchEng.Enabled = false;
  40.         else
  41.             oSearchEng.Enabled = true;
  42.  
  43.         // Loop through all the variables
  44.         for(var v = new Enumerator(oSearchEng.Param()); !v.atEnd(); v.moveNext())
  45.         {
  46.             oParamItem = v.item();
  47.  
  48.             // If parameter is not visible, skip
  49.             if (oParamItem.Visible == true)
  50.             {
  51.                 try
  52.                 {
  53.                     var strParamName    = oParamItem.Name;
  54.  
  55.                     // Read the value from the registry
  56.                     var vValue = pchealth.RegRead( regBase + oSearchEng.ID + "\\" +  strParamName );
  57.  
  58.                     // Load it into the wrapper
  59.                     if(vValue)
  60.                     {
  61.                         var Type = oParamItem.Type;
  62.  
  63.                         // if boolean value
  64.                         if (Type == pchealth.PARAM_BOOL)
  65.                         {
  66.                             if (vValue.toLowerCase() == "true")
  67.                                 oSearchEng.AddParam(strParamName, true);
  68.                             else
  69.                                 oSearchEng.AddParam(strParamName, false);
  70.                         }
  71.                         // if floating numbers
  72.                         else if (Type == pchealth.PARAM_R4 || // float
  73.                                  Type == pchealth.PARAM_R8  ) // double
  74.                         {
  75.                             oSearchEng.AddParam(strParamName, parseFloat(vValue));
  76.                         }
  77.                         // if integer numbers
  78.                         else if (Type == pchealth.PARAM_UI1 || // Byte
  79.                                  Type == pchealth.PARAM_I2  || // Short
  80.                                  Type == pchealth.PARAM_I4  || // long
  81.                                  Type == pchealth.PARAM_INT || // int
  82.                                  Type == pchealth.PARAM_UI2 || // unsigned short
  83.                                  Type == pchealth.PARAM_UI4 || // unsigned long
  84.                                  Type == pchealth.PARAM_UINT)  // unsigned int
  85.                         {
  86.                             oSearchEng.AddParam(strParamName, parseInt(vValue));
  87.                         }
  88.                         else if(Type == pchealth.PARAM_LIST)
  89.                         {
  90.                              LoadListItemToDisplay(oSearchEng, oParamItem.Data, strParamName, vValue);   
  91.                         }
  92.                         // if date, string, selection, etc
  93.                         else
  94.                         {
  95.                             oSearchEng.AddParam(strParamName, vValue);
  96.                         }
  97.                     }                        
  98.                     else
  99.                     {
  100.                         if(oParamItem.Type == pchealth.PARAM_LIST)
  101.                         {
  102.                             LoadListItemToDisplay(oSearchEng, oParamItem.Data, strParamName, "");   
  103.                         }
  104.                     }
  105.                 }
  106.                 catch(e)
  107.                 { ; }
  108.             }
  109.         }
  110.     }
  111. }
  112.  
  113. function SaveWrapperParams(wrapperID, strParamName, vValue)
  114. {
  115.     var reg = g_NAVBAR.GetSearchEngineConfig();
  116.  
  117.     if(wrapperID != "") reg += wrapperID + "\\";
  118.  
  119.      pchealth.RegWrite( reg + strParamName, vValue );
  120. }
  121.  
  122. function LoadListItemToDisplay(oWrapper, strXML, strParameterName, strPrevValue)
  123. {
  124.     try
  125.     {
  126.         var strDefaultItemValue = "";
  127.       
  128.         // Load the xml file
  129.         var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
  130.         xmldoc.async = false;
  131.         xmldoc.loadXML(strXML);        
  132.  
  133.         // Generate each item
  134.         var ElemList = xmldoc.getElementsByTagName("PARAM_VALUE");
  135.      
  136.         for (var i=0; i < ElemList.length; i++)
  137.         {
  138.             var strItemValue = ElemList.item(i).getAttribute("VALUE");
  139.             var strDisplay   = ElemList.item(i).getElementsByTagName("DISPLAYSTRING").item(0).text;
  140.             var strDefault   = ElemList.item(i).getAttribute("DEFAULT");
  141.  
  142.             if(strDefault == null) strDefault = "";
  143.  
  144.             strItemValue = pchealth.TextHelpers.QuoteEscape( strItemValue, "'" );
  145.  
  146.             // Restore the previous value
  147.             if ((!strPrevValue) || (strPrevValue == ""))
  148.             {
  149.                 // Check if default value
  150.                 if(strDefault.toLowerCase() == "true")
  151.                 {
  152.                     // set the default value so that the search wrapper gets this value
  153.                     oWrapper.AddParam( strParameterName, strItemValue );
  154.                     return;
  155.                 }
  156.             }
  157.             else
  158.             {
  159.                 // Check for previous value
  160.                 if(strPrevValue == strItemValue)
  161.                 {
  162.                     // set the prev value so that the search wrapper gets this value
  163.                     oWrapper.AddParam( strParameterName, strItemValue );
  164.                     return;
  165.                 }
  166.                 else
  167.                 {
  168.                     if(strDefault.toLowerCase() == "true")
  169.                     {
  170.                         strDefaultItemValue = strItemValue;
  171.                     }
  172.                 }
  173.             }
  174.         }
  175.  
  176.         // Either add the default value or the first item in the list
  177.         if(strDefaultItemValue.length > 0)
  178.         {
  179.             // set the default value so that the search wrapper gets this value
  180.             oWrapper.AddParam( strParameterName, strDefaultItemValue );
  181.         }
  182.         // Add the first item in the list to wrapper because no default value is present and no prev value is present
  183.         else if(ElemList.length > 0)
  184.         {
  185.             oWrapper.AddParam( strParameterName, ElemList.item(0).getAttribute("VALUE") );
  186.         }
  187.     }
  188.     catch(e)
  189.     {
  190.     }
  191. }
  192.  
  193.